import {omit} from '../utils/utils';
const BasicModel = require('./BasicModel');

module.exports = class Dict extends BasicModel {
  async getAction(params) {
    const data = this.model(params.model).where(params.data).select();
    return data;
  }
  async gettypeAction(params) {
    const data = this.model(params.model).getField('type');
    return data;
  }
  async listallAction(params) {
    let data;
    var arr = Object.keys(params.data);// 传空返回全部数据，不为空选择查询
    if (arr.length !== 0) {
      data = this.order('type').where({...params.data}).select();
      return data;
    } else {
      data = this.order('type').select();
      return data;
    }
  }
  async listpageAction(params) {
    const searchData = omit(params.data, ['page', 'pageSize'], true);
    const { page = 1, pageSize = 20 } = params.data;
    const dataList = await this.order('type').where(searchData).page(page, pageSize).countSelect();
    const {
      currentPage: current,
      totalPages: pages,
      count: total,
      data
    } = dataList;
    const databack = { pageSize, pages, current, total, data };
    return databack;
  }
};
